package com.maori.languageapp.adapter;
import com.maori.languageapp.R;
import android.app.Activity;
import android.app.Dialog;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.media.MediaPlayer;
import android.media.ThumbnailUtils;
import android.media.MediaPlayer.OnPreparedListener;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.MediaController;
import android.widget.ProgressBar;
import android.widget.VideoView;

public class Languageapp_Curate_VideoView_Activity extends Activity{

	VideoView video_view = null;
	String SourceURL;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setFinishOnTouchOutside(false);
		
		super.onCreate(savedInstanceState);
		setContentView(R.layout.languageapp_curate_video_dialog);

		Bundle extras = getIntent().getExtras();
		if (extras != null) {
			SourceURL = extras.getString("SourceURL");
		}
		
		//requestWindowFeature(Window.FEATURE_NO_TITLE);

	    video_view = (VideoView) findViewById(R.id.curate_video_view);
	    
	    final ImageView image_view = (ImageView) findViewById(R.id.thubanail_view);
	    
	    final ProgressBar prog_view = (ProgressBar) findViewById(R.id.progressBar1);

	    String videoFile = "http://langapp.mirzabros.com/lanappvideo/VID_20140507_164454.mp4";
	    Bitmap thumbnail = ThumbnailUtils.createVideoThumbnail(SourceURL,
	            MediaStore.Images.Thumbnails.MINI_KIND);
	    
	    image_view.setImageBitmap(thumbnail);
	    
	    final MediaController mediaController = new MediaController(Languageapp_Curate_VideoView_Activity.this);

	    mediaController.show();
	    
        mediaController.setAnchorView(video_view);
        video_view.setMediaController(mediaController);
	    
        //http://langapp.mirzabros.com/lanappvideo/VID_20140508_123932.mp4
        //video_view.setVideoPath("http://langapp.mirzabros.com/lanappvideo/VID_20140507_173943.3gp");
	    video_view.setVideoURI(Uri.parse(SourceURL));

	    video_view.setZOrderOnTop(true);
	    
	    video_view.requestFocus();

	    image_view.setVisibility(View.VISIBLE);
   	 	prog_view.setVisibility(View.VISIBLE);
   	 	//video_view.setVisibility(View.GONE);
	    
   	 	video_view.setOnTouchListener(new View.OnTouchListener() {
			@Override
			public boolean onTouch(View v, MotionEvent event) {
				mediaController.show();

				return true;
				
			  
			}
   	 	});
   	 	
	    video_view.setOnPreparedListener(new OnPreparedListener() {
             public void onPrepared(MediaPlayer mp) {

            	 //image_view.setVisibility(View.GONE);
            	 prog_view.setVisibility(View.GONE);
            	 image_view.setVisibility(View.GONE);
            	 //video_view.setVisibility(View.VISIBLE);
            	 video_view.start();
             }
            });
	    
	}
	
	@Override
	public void onBackPressed() {
		super.onBackPressed();
		video_view.stopPlayback();
	}
}
